package MoC;

import java.util.LinkedList;
import java.util.Iterator;

import db.*;
import sr.SRDepGraph;

//////////////////////////////////////////////////////////////////////////
//// CompositeActorResult
/**

@author Ivan Jeukens
@version v 0.1 25/06/2003
*/
public class CompositeActorResult {

    public CompositeActorResult(CompositeActorInfo info) {
        _info = info;

        _associatedDirectors = new LinkedList();
        _toVerify = new LinkedList();

        _validAsAtomicActorFor = new LinkedList();
        _isSRHomogeneous = false;

        _isSDFSchedulable = false;
    }

    ///////////////////////////////////////////////////////////////////
    ////                      public variables                     ////

    ///////////////////////////////////////////////////////////////////
    ////                        public methods                     ////

    public void initialize(LinkedList mocs) {
        for(int i = 0;i < mocs.size();i++) {
            MoCVerifier mocver = (MoCVerifier) mocs.get(i);
            _toVerify.add(mocver.getName());
        }
    }

    public boolean isSpecific() {
        return _isSpecific;
    }

    // Se for o caso, o nome do modelo
    public String getSpecificMoC() {
        return _specificMoC;
    }

    public void setSpecificMoC(String name) {
        _specificMoC = name;
        _isSpecific = true;
    }
    
    public boolean hasError() {
        return _hasError;
    }

    public void setHasError(boolean value) {
        _hasError = value;
    }

    public String getName() {
        return _info.getName();
    }

    public CompositeActorInfo getInfo() {
        return _info;
    }

    public void addAssociatedDirector(String name) {
        if(!_associatedDirectors.contains(name)) {
            _associatedDirectors.add(name);
        }
    }

    public Iterator associatedDirectors() {
        return _associatedDirectors.iterator();
    }

    public boolean isValidAsAtomicActorFor(String moc) {
        return _validAsAtomicActorFor.contains(moc);
    }
    
    public Iterator toVerifyIterator() {
        return _toVerify.iterator();
    }

    public Iterator validAsAtomicActorForIterator() {
        return _validAsAtomicActorFor.iterator();
    }

    public void setValidAsAtomicActorFor(String moc) {
        if(!isValidAsAtomicActorFor(moc)) {
            _validAsAtomicActorFor.add(moc);
        }
    }

    public int toVerifySize() {
        return _toVerify.size();
    }    

    public int validAsAtomicActorForSize() {
        return _validAsAtomicActorFor.size();
    }
    
    public void setSRDepGraph(SRDepGraph graph) {
        _graph = graph;
    }
    
    public SRDepGraph getSRDepGraph() {
        return _graph;
    }

    public String toString() {
        StringBuffer ret = new StringBuffer("CompositeActorResult for " + 
            _info.getName() + "\n");

        ret.append("Directors: ");
        for(int i = 0;i < _associatedDirectors.size();i++) {
            String s = (String) _associatedDirectors.get(i);
            ret.append(s + " ");
        }
        ret.append("\n");

        ret.append("To Verify: ");
        for(int i = 0;i < _toVerify.size();i++) {
            String s = (String) _toVerify.get(i);
            ret.append(s + " ");
        }
        ret.append("\n");

        ret.append("Valis as Atomic For: ");
        for(int i = 0;i < _validAsAtomicActorFor.size();i++) {
            String s = (String) _validAsAtomicActorFor.get(i);
            ret.append(s + " ");
        }

        return ret.toString();
    }

    public void setSRHomogeneous() {
        _isSRHomogeneous = true;
    }

    public boolean isSRHomogeneous() {
        return _isSRHomogeneous;
    }

    public void setSDFSchedulable() {
        _isSDFSchedulable = true;
    }
    
    public boolean isSDFSchedulable() {
        return _isSDFSchedulable;
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private variables                  ////

    private CompositeActorInfo _info;

    private LinkedList _associatedDirectors;
    private LinkedList _toVerify;

    private LinkedList _validAsAtomicActorFor;

    private boolean _hasError;

    private boolean _isSpecific;
    private String _specificMoC;

    private boolean _isSRHomogeneous;
    private SRDepGraph _graph;

    private boolean _isSDFSchedulable;
}
